//
//  DynamicCast.hpp
//  learnC++
//
//  Created by liuzhibing on 2018/6/19.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#ifndef DynamicCast_hpp
#define DynamicCast_hpp

#include <stdio.h>
#include <iostream>

class Base12 {
protected:
    int m_value;
    
public:
    
    Base12(int value):m_value(value){
        std::cout << "XXX\n";
    }
    
    virtual ~Base12(){}
    
};

class Derived12 : public Base12 {
    
    const char *m_name;
    
public:
    Derived12(int value = 0,const char *name = ""):Base12(value),m_name(name){
        
    }
    
    const char *getName(){return m_name;}
    
    virtual ~Derived12(){}
};

Base12* getObject(bool bReturnDerived);

//尽管动态转换具有几种不同的功能，但到目前为止，动态转换最常用的用途是将基类指针转换为派生类指针。 这个过程称为向下转换。
/*
 Base12 *b = getObject(true);
 
 Derived12 *d = dynamic_cast<Derived12 *>(b);
 
 if (d) {
 std::cout << d->getName();
 }
 
 delete b;
 */


#endif /* DynamicCast_hpp */
